function [str] = mainLoop()
    global isWorking
    
    javaaddpath('modelingModuleClient.jar')
    javaaddpath('mysql-connector-java-5.1.22-bin.jar')
    import ifmo.group5512.timer.modelingClient.*;
    
    
    client = ModelingModuleClient;
    
    str = 'Start work'
    
    CON = struct ('connectorPath', 'mysql-connector-java-5.1.22-bin.jar', 'host', 'localhost', 'port', '3306', 'dbname', 'KIS', 'user', 'root', 'password', '', 'usingDB', 'KIS');
   
    tactsInDay = 24;
    
    isWorking = true;
    while (client.isValid && isWorking == true) 
        status = client.lock()
        
        if (status == Action.WritingRequest)
            imitateOrders(CON);
        else
            if (status == Action.Modeling)
                evalCurrentDay(CON, client.getTime, tactsInDay);
                imitateDelaysChanges(CON);
                imitateManufacturing(CON);
				buildGraphs(CON, client.getTime, tactsInDay);
            end;
        end;
        str = 'work'
        client.unlock()
        
        pause(3)
    end;
end